<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!doctype html>
<html class="bg-white">
<head>
<meta charset="utf-8">
<title>三伏贴预约</title>
<link type="text/css" rel="stylesheet" href="${yyghStatic}/modules/yygh/css/mobiscroll.2.13.2.css?rev=25879f12ca807894"/>
<%@ include file="/WEB-INF/views/include/head_mobile.jsp" %>
</head>
<body class="${sessionScope.SESSION_KEY_THIRD_CHANNEL.isNav==1?'pdt90':''}">
<c:if test="${not empty message}">
	<script type="text/javascript">
		layer.alert('${message}');
	</script>
</c:if>
<div class="ui-main pdb220">
    <div class="header-nav">
<%--        <a href="javascript:void(0)" class="h-left" id="btn_goback">--%>
<%--            <i class="ui-trigger"></i>返回</a>--%>
        <span id="id_nav_title" style="padding-right:0.3rem">三伏贴预约</span>
    </div>
	<form action="${pageContext.request.contextPath}/mx/gfaj/save" id="myfrm" name="myfrm" method="post">
	<input type="hidden" name="code" id="code" value="${code}"/>
        <input type="hidden" name="userName" id="userName" value="${userName}"/>
	<input type="hidden" name="mobile" id="mobile" value="${mobile}" />
	<input type="hidden" name="userType" id="userType" value="${type}" />
        <input type="hidden" name="equityCode" id="equityCode" value="${equityCode}" />
    <div class="common-flex-box pd0-45 border-bottom bg-white">
        <div class="common-flex-item border-bottom">
            <i class="ui-trigger trig-down"></i>
            <div class="common-flex-left">预约门店</div>
            <div class="common-flex-right">
                <select class="common-select" name="tenantId" id="tenantId" onchange="changeSelect()">
                    <option value="15" ${tenantId =="15"?'selected':''}>瑞来春堂福州瑞承馆(暂停预约)</option>
                    <option value="4" ${tenantId =="4"?'selected':''}>福州瑞来春堂澳门路馆(暂停预约)</option>
                    <option value="1" ${tenantId =="1"?'selected':''}>福州瑞来春堂三坊七巷馆(暂停预约)</option>
                    <option value="2" ${tenantId =="2"?'selected':''}>福州瑞来春堂仓山馆(暂停预约)</option>
                    <option value="3" ${tenantId =="3"?'selected':''}>福州瑞来春堂华林巷馆(暂停预约)</option>
                    <option value="5" ${tenantId =="5"?'selected':''}>泉州瑞来春堂丰泽馆(暂停预约)</option>
                    <option value="6" ${tenantId =="6"?'selected':''}>三明瑞来春堂列东馆(暂停预约)</option>
                    <option value="7" ${tenantId =="7"?'selected':''}>龙岩瑞来春堂新罗馆(暂停预约)</option>
                    <option value="8" ${tenantId =="8"?'selected':''}>宁德树德堂中医馆(暂停预约)</option>
                    <option value="9" ${tenantId =="9"?'selected':''}>福州博方堂中医门诊部(暂停预约)</option>
                    <option value="10" ${tenantId =="10"?'selected':''}>福州博方堂中医门诊部(暂停预约)</option>
                    <option value="11" ${tenantId =="11"?'selected':''}>南平本草堂中医诊所(暂停预约)</option>
                    <option value="12" ${tenantId =="12"?'selected':''}>漳州市永欣堂中医馆(暂停预约)</option>
                    <option value="13" ${tenantId =="13"?'selected':''}>漳州市平和永欣门诊部(暂停预约)</option>
                    <option value="14" ${tenantId =="14"?'selected':''}>莆田市善痛堂理疗服务中心(暂停预约)</option>
                </select>
            </div>
        </div>
        <div class="common-flex-item">
            <div class="common-flex-left">初伏</div>
            <div class="common-flex-right">
                <input type="text" name="orderDate" id="orderDateChu" value="${orderDateChu}"  onchange="handleInputChu()" class="common-input-text date-time-input-chu" placeholder="请输入预约时间" />
            </div>
        </div>
        <div class="common-flex-item">
            <div class="common-flex-left">中伏</div>
            <div class="common-flex-right">
                <input type="text" name="orderDate" id="orderDateZhong" value="${orderDateZhong}" onchange="handleInputZhong()" class="common-input-text date-time-input-zhong" placeholder="请输入预约时间" />
            </div>
        </div>
        <div class="common-flex-item">
            <div class="common-flex-left">末伏</div>
            <div class="common-flex-right">
                <input type="text" name="orderDate" id="orderDateMo" value="${orderDateMo}"  class="common-input-text date-time-input-mo" placeholder="请输入预约时间" />
            </div>
        </div>
    </div>
    </form>
    <div class="index-tip">
        <font id="title">瑞来春堂福州瑞承馆(暂停预约)</font><br />
        服务地址：<font id="address">福州市鼓楼区澳门路63号（民生银行隔壁）</font><br/>
        服务时间：<font id="date">8:30-12:00 14:30-17:30</font><br />
        温馨提示：<br />
        1.请确保信息真实有效，以免影响正常就诊！<br />
        2.预约成功后，为确保到店时避开高峰时段，请联系客服确认到医馆使用服务的时间；服务热线：18558838821（8:30--18:00)
    </div>
</div>
<div class="fixed-bottom">
    <div class="pd60-100">
        <a href="javascript:void(0)" class="common-btn btn-main-grid btn-radius" id="btn_save">保存</a>
    </div>
</div>
</body>
<script type="text/javascript" src="${yyghStatic}/modules/yygh/js/mobiscroll.2.13.2.js"></script>
<script type="text/javascript" src="${yyghStatic}/modules/yygh/js/ui_mobiscroll.js"></script>
<script type="text/javascript">
	function showMsg(msg) {
		layer.alert(msg);
	}

    function changeSelect() {
        let select = $('#tenantId option:selected').val()
        let tenantName = $('#tenantId option:selected').text()
        if(select == 1){
            $("#address").text('鼓楼区三坊七巷南后街4-6号')
            $("#title").text(tenantName)
            $("#date").text('8:30-12:00 14:30-17:30')
        }else if(select == 2){
            $("#address").text('仓山区仓山万达广场C3号楼27商铺')
            $("#title").text(tenantName)
            $("#date").text('8:30-18:00')
        }else if(select == 3){
            $("#address").text('鼓楼区华林路246号二楼')
            $("#title").text(tenantName)
            $("#date").text('8:30-18:00')
        }else if(select == 4){
            $("#address").text('鼓楼区澳门路26号')
            $("#title").text(tenantName)
            $("#date").text('8:30-12:00 14:30-17:30')
        }else if(select == 5){
            $("#address").text('丰泽区东海湾和园东北1门西北230米')
            $("#title").text(tenantName)
            $("#date").text('8:30-18:00')
        }else if(select == 6){
            $("#address").text('三明市三元区列东街 38号')
            $("#title").text(tenantName)
            $("#date").text('8:30-18:00')
        }else if(select == 7){
            $("#address").text('新罗区溪南路37号办公楼')
            $("#title").text(tenantName)
            $("#date").text('8:30-18:00')
        }else if(select == 8){
            $("#address").text('宁德蕉城区八一五中路前林路一号二层')
            $("#title").text(tenantName)
            $("#date").text('9:00-17:00（周二休息）')
        }else if(select == 9){
            $("#address").text('福州市台江区广达路393号边达大厦2层')
            $("#title").text(tenantName)
            $("#date").text('8:30-17:00')
        }else if(select == 10){
            $("#address").text('福州市鼓楼区鼓西路396号西湖好美家4号楼2层')
            $("#title").text(tenantName)
            $("#date").text('8:30-17:00')
        }else if(select == 11){
            $("#address").text('南平市建阳区建发二期书院南路77-6')
            $("#title").text(tenantName)
            $("#date").text('8:30-17:00')
        }else if(select == 12){
            $("#address").text('漳州市芗城区腾飞路372-2')
            $("#title").text(tenantName)
            $("#date").text('8:30-21:30')
        }else if(select == 13){
            $("#address").text('漳州市平和县小溪镇河滨北路96号')
            $("#title").text(tenantName)
            $("#date").text('8:30-21:00')
        }else if(select == 14){
            $("#address").text('莆田市荔城区阔口小区31号楼117号')
            $("#title").text(tenantName)
            $("#date").text('9:00-21:00')
        }else if(select == 15){
            $("#address").text('福州市鼓楼区澳门路63号（民生银行隔壁）')
            $("#title").text(tenantName)
            $("#date").text('9:00-21:00')
        }
    }

	let flag = false;
    $(function(){
        changeSelect()
    	$("#btn_save").click(function(){
			showMsg('活动已暂停预约！');
                return false;
    	    if($("#orderDateChu").val() == '' && $("#orderDateZhong").val() == '' && $("#orderDateMo").val() == ''){
                showMsg('请输入预约时间！');
                return false;
            }
    	    if($('#tenantId option:selected').val() == 1){
                showMsg('福州瑞来春堂三坊七巷馆已约满！');
                return false;
            }
            if($('#tenantId option:selected').val() == 2){
                showMsg('福州瑞来春堂仓山馆已约满！');
                return false;
            }
            if($('#tenantId option:selected').val() == 4){
                showMsg('福州瑞来春堂澳门馆已约满！');
                return false;
            }
            // if($('#tenantId option:selected').val() == 2){
            //     showMsg('福州瑞来春堂仓山馆已约满！');
            //     return false;
            // }
            if(new Date($("#orderDateZhong").val()) < new Date($("#orderDateChu").val())){
                showMsg('中伏时间应该大于初伏！');
                return false;
            }
    	    if(new Date($("#orderDateMo").val()) < new Date($("#orderDateZhong").val())){
                showMsg('末伏时间应该大于中伏！');
                return false;
            }
    	    if($('#tenantId option:selected').val() == 8 && (new Date($("#orderDateChu").val()).getDay()) == 2
                || new Date($("#orderDateChu").val()).getDay() == 2 || new Date($("#orderDateChu").val()).getDay() == 2
            ){
                showMsg('树德堂中医馆周二休息，请修改预约时间！');
                return false;
            }
    	    if(flag){
    	        return;
            }
    	    flag = true;
            $.ajax({
                type : "post",
                url:'${pageContext.request.contextPath}/mx/sfj/save',
                data :'code='+$("#code").val()+'&userName='+$("#userName").val()+'&mobile='+$("#mobile").val()+'&userType='+$("#userType").val()+'&tenantId='+$('#tenantId option:selected').val()+'&tenantName='+$('#tenantId option:selected').text()+'&orderDateChu='+$('#orderDateChu').val()+'&orderDateZhong='+$('#orderDateZhong').val()+'&orderDateMo='+$('#orderDateMo').val()+'&equityCode='+$('#equityCode').val(),
                contentType: "application/x-www-form-urlencoded;charset=utf-8",
                success:function(data){
                    setTimeout(
                        function(){
                        flag = false;
                    }, 2000)
                    if(data.code == '0'){
                        showMsg('操作成功！');
                    }else{
                        showMsg(data.error);
                    }
                },
                error:function(re,e,ex){
                    layer.alert('请求异常:'+re.status);
                }
            });
    	});
        let today = new Date()
        today.setDate(today.getDate()+1)
        today.setHours(8)
        today.setMinutes(30)
    	PLUGINSCROLL.MOBILE_DATE_SCROLL.mobileScrollDateTime($('.date-time-input-chu'),new Date('2023/09/30 17:00'), today, function() {
            var date = new Date($('#orderDateChu').val())
            if (($('#tenantId option:selected').val() == 12 || $('#tenantId option:selected').val() == 13 || $('#tenantId option:selected').val() == 14)
                && (date.getHours() > 21 || ( date.getHours() == 21 && date.getMinutes() != 0))) {
                $('#orderDateChu').val("");
                showMsg('最晚预约时间为21:00！');
                return false;
            }
            if (date.getHours() > 17 || ( date.getHours() == 17 && date.getMinutes() != 0)) {
                $('#orderDateChu').val("");
                showMsg('最晚预约时间为17:00！');
            }
        })
        PLUGINSCROLL.MOBILE_DATE_SCROLL.mobileScrollDateTime($('.date-time-input-zhong'),new Date('2023/10/10'), new Date('2023/07/22 08:30'),function(){
            var date = new Date($('#orderDateZhong').val())
            if (($('#tenantId option:selected').val() == 12 || $('#tenantId option:selected').val() == 13 || $('#tenantId option:selected').val() == 14) && (date.getHours() > 21 || ( date.getHours() == 21 && date.getMinutes() != 0))) {
                $('#orderDateZhong').val("");
                showMsg('最晚预约时间为21:00！');
                return false;
            }
            if (date.getHours() > 17 || ( date.getHours() == 17 && date.getMinutes() != 0)) {
                $('#orderDateZhong').val("");
                showMsg('最晚预约时间为17:00！');
            }
        });
        PLUGINSCROLL.MOBILE_DATE_SCROLL.mobileScrollDateTime($('.date-time-input-mo'),new Date('2023/10/20'),new Date('2023/08/01 08:30'),function(){
            var date = new Date($('#orderDateMo').val())
            if (($('#tenantId option:selected').val() == 12 || $('#tenantId option:selected').val() == 13 || $('#tenantId option:selected').val() == 14) && (date.getHours() > 21 || ( date.getHours() == 21 && date.getMinutes() != 0))) {
                $('#orderDateMo').val("");
                showMsg('最晚预约时间为21:00！');
                return false;
            }
            if (date.getHours() > 17 || ( date.getHours() == 17 && date.getMinutes() != 0)) {
                $('#orderDateMo').val("");
                showMsg('最晚预约时间为17:00！');
            }
        });

    });
	function handleInputChu() {
        let test = $('#orderDateChu').val();
        if(test == '2023-07-11'){
            test = '2023-07-12'
        }
        let today = new Date()
        today.setDate(new Date(test).getDate()+1)
        today.setHours(8)
        today.setMinutes(30)
        today.setDate(new Date(test).getDate()+9)
        PLUGINSCROLL.MOBILE_DATE_SCROLL.mobileScrollDateTime($('.date-time-input-zhong'),new Date('2023/10/10'),
            today,function(){
                var date = new Date($('#orderDateZhong').val())
                if (($('#tenantId option:selected').val() == 12 || $('#tenantId option:selected').val() == 13 || $('#tenantId option:selected').val() == 14) && (date.getHours() > 21 || ( date.getHours() == 21 && date.getMinutes() != 0))) {
                    $('#orderDateZhong').val("");
                    showMsg('最晚预约时间为21:00！');
                    return false;
                }
                if (date.getHours() > 17 || ( date.getHours() == 17 && date.getMinutes() != 0)) {
                    $('#orderDateZhong').val("");
                    showMsg('最晚预约时间为17:00！');
                }
        });
        // today.setDate(new Date(test).getDate()+9)
        // $('#orderDateZhong').val(dateFormat('YYYY-mm-dd HH:MM', today));
        // today.setDate(today.getDate()+10)
        // $('#orderDateMo').val(dateFormat('YYYY-mm-dd HH:MM', today));
    }
    function handleInputZhong() {
        let test = $('#orderDateZhong').val();
        let today = new Date(test)
        today.setDate(today.getDate()+1)
        today.setHours(8)
        today.setMinutes(30)
        today.setDate(today.getDate()+9)
        PLUGINSCROLL.MOBILE_DATE_SCROLL.mobileScrollDateTime($('.date-time-input-mo'),new Date('2023/10/20'),
            today,function(){
                var date = new Date($('#orderDateMo').val())
                if (($('#tenantId option:selected').val() == 12 || $('#tenantId option:selected').val() == 13 || $('#tenantId option:selected').val() == 14) && (date.getHours() > 21 || ( date.getHours() == 21 && date.getMinutes() != 0))) {
                    $('#orderDateMo').val("");
                    showMsg('最晚预约时间为21:00！');
                    return false;
                }
                if (date.getHours() > 17 || ( date.getHours() == 17 && date.getMinutes() != 0)) {
                    $('#orderDateMo').val("");
                    showMsg('最晚预约时间为17:00！');
                }
            });
        // today.setDate(today.getDate()+9)
        // $('#orderDateMo').val(dateFormat('YYYY-mm-dd HH:MM', today));
    }
    function dateFormat(fmt, date) {
        let ret;
        const opt = {
            "Y+": date.getFullYear().toString(),        // 年
            "m+": (date.getMonth() + 1).toString(),     // 月
            "d+": date.getDate().toString(),            // 日
            "H+": date.getHours().toString(),           // 时
            "M+": date.getMinutes().toString(),         // 分
            "S+": date.getSeconds().toString()          // 秒
            // 有其他格式化字符需求可以继续添加，必须转化成字符串
        };
        for (let k in opt) {
            ret = new RegExp("(" + k + ")").exec(fmt);
            if (ret) {
                fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
            };
        };
        return fmt;
    }

</script>
</html>
